<link rel="import" href="../../../../packages/polymer/polymer.html">
<link rel="import" href="nav_bar.html">
<link rel="import" href="observatory_element.html">
<link rel="import" href="view_footer.html">

<polymer-element name="vm-connect-target" extends="observatory-element">
  <template>
    <style>
      .delete-button {
        padding: 4px;
        background: transparent;
        border: none !important;
      }
      .delete-button:hover {
        background: #ff0000;
      }
    </style>
    <link rel="stylesheet" href="css/shared.css">
    <span>
      <template if="{{ isCurrentTarget }}">
        <a on-click="{{ connectToVm }}" _href="{{ gotoLinkForwardingParameters('/vm') }}">{{ target.name }} (Connected)</a>
      </template>
      <template if="{{ !isCurrentTarget }}">
        <a on-click="{{ connectToVm }}" _href="{{ gotoLinkForwardingParameters('/vm') }}">{{ target.name }}</a>
      </template>
      <button class="delete-button" on-click="{{ deleteVm }}">&#10006; Remove</button>
    </span>
  </template>
</polymer-element>

<polymer-element name="vm-connect" extends="observatory-element">
  <template>
    <link rel="stylesheet" href="css/shared.css">
    <style>
      .textbox {
        width: 20em;
        font: 400 16px 'Montserrat', sans-serif;
      }
    </style>

    <nav-bar>
      <top-nav-menu last="{{ true }}"></top-nav-menu>
    </nav-bar>

    <div class="content-centered">
      <h1>Connect to a Dart VM</h1>
      <br>
      <hr>
      <div class="flex-row">
        <div class="flex-item-40-percent">
          <h2>WebSocket</h2>
          <br>
          <ul>
            <template repeat="{{ target in app.targets.history }}">
              <template if="{{ target.standalone }}">
                <li><vm-connect-target target="{{ target }}"></vm-connect-target></li>
              </template>
            </template>
          </ul>
          <hr>
          <form autocomplete="on">
            <input class="textbox" placeholder="localhost:8181" type="text" value="{{ standaloneVmAddress }}">
            <input class="button" type="submit" value="Connect" on-click="{{ connectStandalone }}">
          </form>
          <br>
          <pre class="well">Run Standalone with: '--observe'</pre>
          <hr>
        </div>

        <div class="flex-item-20-percent"></div>
        <div class="flex-item-40-percent">
          <h2>Crash dump</h2>
          <br>
          <input type="file" id="crashDumpFile">
          <br>
          <br>
          <pre class="well">Request a crash dump with:
'curl localhost:8181/_getCrashDump > dump.json'</pre>
          <hr>
        </div>
      </div>
    </div>
    <view-footer></view-footer>
  </template>
</polymer-element>

<script type="application/dart" src="vm_connect.dart"></script>
